﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Helper;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.XT;
using Rison.BusinessFacade.Facade.XT;
using Rison.BusinessFacade.Facade.Biz;

namespace Rison.Web.ascx
{
    public partial class InfoContainer1_2 : System.Web.UI.UserControl
    {
        //在调用页面的Page_Init时传入该值
        public int tableWidth = 240;
        public int tableHeight = 210;
      
        public int moduleId = 0;//要绑定的二级菜单的ID
        public bool displayDate = true;//是否显示日期
        public int displayRows = 6;
        public int maxSubjectLength = 0;//信息框中信息标题的显示长度，0为不截取

        public bool SetGridBackColor = false;

        protected string UrlBase
        {
            get { return PageGlobalParams.PageUrlBase; }
        }

        protected string titleWidth
        {
            get { return (tableWidth - 60-4).ToString() + "px"; }
        }
        
        protected string contentRowHeitht
        {
            get { return (tableHeight - 21-2).ToString() + "px"; }
        }

        public string titleBgColor
        {
            get { return ""; }
        }

        public string contentBgColor
        {
            get { return ""; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindModule();
            }
        }

        private void BindModule()
        {
            this.dlInfos.DataSource = new SysModuleFacade().GetDataBy("MID=" + moduleId.ToString());
            this.dlInfos.DataBind();
        }

        protected void dlInfos_OnItemDataBound(object sender, DataListItemEventArgs e)
        {
            foreach (Control c in e.Item.Controls)
            {
                if (c.GetType().Name == "GridView")
                {
                    if (!displayDate)
                        (c as GridView).Columns[2].Visible = false;

                    if (SetGridBackColor == true)
                        (c as GridView).Style.Add("background-color", "#ddeff9");

                    BindInfos(c as GridView);
                }
            }
        }

        private void BindInfos(GridView gvInfo)
        {
            gvInfo.DataSource = new InfomationFacade().GetTopNumInfos(moduleId, displayRows, maxSubjectLength);
            gvInfo.DataBind();
        }
    }
}